#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include <errno.h>

#include "sans.h"

#define MAX_SYMBOLS 4096

u num_symbols = 0;
char* symboltable[MAX_SYMBOLS];

char* lookup(u ref) {
  if (ref < num_symbols) {
    return symboltable[ref];
  }
  else {
    log_err("symboltable/lookup: %lu out of bounds %lu\n", ref, num_symbols);
  }
}

u intern(char *name) {
  u i;
  
  for (i = 0; i < num_symbols; i++) {
    if (!strcmp(symboltable[i], name)) {
      return i;
    }
  }
  
  symboltable[num_symbols] = malloc(strlen(name)+1);
  if (!symboltable[num_symbols]) {
    log_err("symboltable/intern: malloc failure\n");
  }
  
  strcpy(symboltable[num_symbols], name);
  return num_symbols++;
}
